﻿
#region Using

using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using Rio.Manager.Application.ViewModel.BaseClass;
using Rio.Framework.Localisation;
using System;
using System.Collections.ObjectModel;
using Rio.Applications.Web.Services;
using System.ServiceModel.DomainServices.Client;
using System.Windows;

using Rio.Manager.Application.ViewModel.Locator;
using Rio.Framework.Pages.Helpers;
using Rio.Framework.Pages.Context;
using NetBay.Core.BusinessEntities;
using Rio.Framework.Pages.AppCode.Enums;
using NetBay.Core.BusinessEntities.Barcodes;
using System.Linq;
using Rio.Framework.Pages;
using Rio.Manager.Application.Model;
using System.Collections.Generic;

#endregion Using

namespace Rio.Manager.Application.ViewModel.Administration
{
    public class BarCodeTabViewModel : TabViewModelBase
    {
        #region Fields

        public RelayCommand InitializationCommand { get; set; }
        public RelayCommand BarCodeCreateCommand { get; set; }
        public RelayCommand BarCodeActivateDeactiveCommand { get; set; }
        public RelayCommand BarCodeModifyCommand { get; set; }
        public RelayCommand BarCodeDeleteCommand { get; set; }
        public RelayCommand BarCodeRefreshCommand { get; set; }

        private string _BarCodeTitleList;
        private string _NewBarCode;
        private string _ActivateBarCode;
        private string _ModifyBarCode;
        private string _DeleteBarCode;
        private string _RefreshBarCode;
        private Boolean _CanAddBarCode;
        private Boolean _CanActivateBarCode;
        private Boolean _CanUpdateBarCode;
        private Boolean _CanDeleteBarCode;
        private Boolean _CanRefreshBarCode;
        private Boolean _ActiveBarCodeStatut;
        private ObservableCollection<Barcode> _BarCodeInformationList;
        private ObservableCollection<Barcode> _BarCodeInformationsSelected;
        private string _HeaderBarCodeEnable;
        private string _HeaderBarCodeParamCode;
        private string _HeaderBarCodeName;
        private string _HeaderBarCodeDescription;
        private string _HeaderBarCodePrefix;
        private string _HeaderBarCodeType;
        private string _HeaderBarCodeFunction;
        private Boolean _RadTabItemSepDocumentIsEnabled;
        private Boolean _RadTabItemSepDocumentIsSelected;
        private string _RadTabItemHeaderSepDocument;
        private string _SepDocItemList;
        private string _HeaderBarCodeSeparatorDocumentId;
        private string _HeaderBarCodeSeparatorDocumentNatureName;
        private string _HeaderBarCodeSeparatorDocumentItemName;
        private string _HeaderBarCodeSeparatorDocumentPdfMerge;
        private string _HeaderBarCodeSeparatorDocumentDeleteBarCodePage;
        private string _HeaderBarCodeSeparatorDocumentManageError;
        private string _HeaderBarCodeSeparatorDocumentInfLimit;
        private string _HeaderBarCodeSeparatorDocumentSupLimit;
        private Boolean _RadTabItemSepFolderIsEnabled;
        private Boolean _RadTabItemSepFolderIsSelected;
        private string _RadTabItemHeaderSepFolder;
        private string _SepFolderItemList;
        private string _HeaderBarCodeSeparatorFolderCorresp;
        private string _HeaderBarCodeSeparatorFolderIndexname;
        private string _HeaderBarCodeSeparatorFolderIndexStartChar;
        private string _HeaderBarCodeSeparatorFolderIndexEndChar;
        private string _HeaderBarCodeSeparatorFolderDocLimit;
        private string _HeaderBarCodeSeparatorFolderPageLimit;
        private string _HeaderBarCodeSeparatorFolderDocumentLimit;
        private string _HeaderBarCodeSeparatorFolderInfLimit;
        private string _HeaderBarCodeSeparatorFolderSupLimit;
        private string _HeaderBarCodeSeparatorFolderDeleteCAB;
        private string _HeaderBarCodeSeparatorFolderErrorManagment;
			
        #endregion Fields

        #region Properties

        public string BarCodeTitleList
        {
            get { return _BarCodeTitleList; }
            set
            {
                _BarCodeTitleList = value;
                RaisePropertyChanged("BarCodeTitleList");
            }
        }
        
        public string NewBarCode
        {
            get { return _NewBarCode; }
            set
            {
                _NewBarCode = value;
                RaisePropertyChanged("NewBarCode");
            }
        }

        public string ActivateBarCode
        {
            get { return _ActivateBarCode; }
            set
            {
                _ActivateBarCode = value;
                RaisePropertyChanged("ActivateBarCode");
            }
        }

        public string ModifyBarCode
        {
            get { return _ModifyBarCode; }
            set
            {
                _ModifyBarCode = value;
                RaisePropertyChanged("ModifyBarCode");
            }
        }

        public string DeleteBarCode
        {
            get { return _DeleteBarCode; }
            set
            {
                _DeleteBarCode = value;
                RaisePropertyChanged("DeleteBarCode");
            }
        }

        public string RefreshBarCode
        {
            get { return _RefreshBarCode; }
            set
            {
                _RefreshBarCode = value;
                RaisePropertyChanged("RefreshBarCode");
            }
        }

        public Boolean ActiveBarCodeStatut
        {
            get { return _ActiveBarCodeStatut; }
            set {
                _ActiveBarCodeStatut = value;
                RaisePropertyChanged("ActiveBarCodeStatut");
            }
        }

        public Boolean CanAddBarCode
        {
            get { return _CanAddBarCode; }
            set
            {
                _CanAddBarCode = value;
                RaisePropertyChanged("CanAddBarCode");
            }
        }

        public Boolean CanActivateBarCode
        {
            get { return _CanActivateBarCode; }
            set
            {
                _CanActivateBarCode = value;
                RaisePropertyChanged("CanActivateBarCode");
                SetJobBarCodeCmdActivateDeactivate(value);
            }
        }

        public Boolean CanUpdateBarCode
        {
            get { return _CanUpdateBarCode; }
            set
            {
                _CanUpdateBarCode = value;
                RaisePropertyChanged("CanUpdateBarCode");
            }
        }

        public Boolean CanDeleteBarCode
        {
            get { return _CanDeleteBarCode; }
            set
            {
                _CanDeleteBarCode = value;
                RaisePropertyChanged("CanDeleteBarCode");
            }
        }

        public Boolean CanRefreshBarCode
        {
            get { return _CanRefreshBarCode; }
            set
            {
                _CanRefreshBarCode = value;
                RaisePropertyChanged("CanRefreshBarCode");
            }
        }

        public ObservableCollection<Barcode> BarCodeInformationList
        {
            get { return _BarCodeInformationList; }
            set 
            { 
                _BarCodeInformationList = value;
                RaisePropertyChanged("BarCodeInformationList");
            }
        }

        public ObservableCollection<Barcode> BarCodeInformationsSelected
        {
            get { return _BarCodeInformationsSelected; }
            set
            {
                _BarCodeInformationsSelected = value;
                RaisePropertyChanged("BarCodeInformationsSelected");
            }
        }

        public string HeaderBarCodeEnable
        {
            get { return _HeaderBarCodeEnable; }
            set 
            { 
                _HeaderBarCodeEnable = value;
                RaisePropertyChanged("HeaderBarCodeEnable");
            }
        }

        public string HeaderBarCodeParamCode
        {
            get { return _HeaderBarCodeParamCode; }
            set 
            { 
                _HeaderBarCodeParamCode = value;
                RaisePropertyChanged("HeaderBarCodeParamCode");
            }
        }

        public string HeaderBarCodeName
        {
            get { return _HeaderBarCodeName; }
            set 
            { 
                _HeaderBarCodeName = value;
                RaisePropertyChanged("HeaderBarCodeName");
            }
        }

        public string HeaderBarCodeDescription
        {
            get { return _HeaderBarCodeDescription; }
            set 
            { 
                _HeaderBarCodeDescription = value;
                RaisePropertyChanged("HeaderBarCodeDescription");
            }
        }

        public string HeaderBarCodePrefix
        {
            get { return _HeaderBarCodePrefix; }
            set 
            { 
                _HeaderBarCodePrefix = value;
                RaisePropertyChanged("HeaderBarCodePrefix");
            }
        }

        public string HeaderBarCodeType
        {
            get { return _HeaderBarCodeType; }
            set 
            { 
                _HeaderBarCodeType = value;
                RaisePropertyChanged("HeaderBarCodeType");
            }
        }

        public string HeaderBarCodeFunction
        {
            get { return _HeaderBarCodeFunction; }
            set 
            { 
                _HeaderBarCodeFunction = value;
                RaisePropertyChanged("HeaderBarCodeFunction");
            }
        }

        public Boolean RadTabItemSepDocumentIsEnabled
        {
            get { return _RadTabItemSepDocumentIsEnabled; }
            set
            {
                _RadTabItemSepDocumentIsEnabled = value;
                RaisePropertyChanged("RadTabItemSepDocumentIsEnabled");
            }
        }

        public Boolean RadTabItemSepDocumentIsSelected
        {
            get { return _RadTabItemSepDocumentIsSelected; }
            set
            {
                _RadTabItemSepDocumentIsSelected = value;
                RaisePropertyChanged("RadTabItemSepDocumentIsSelected");
            }
        }

        public string RadTabItemHeaderSepDocument
        {
            get { return _RadTabItemHeaderSepDocument; }
            set
            {
                _RadTabItemHeaderSepDocument = value;
                RaisePropertyChanged("RadTabItemHeaderSepDocument");
            }
        }

        public string SepDocItemList
        {
            get { return _SepDocItemList; }
            set
            {
                _SepDocItemList = value;
                RaisePropertyChanged("SepDocItemList");
            }
        }

        public string HeaderBarCodeSeparatorDocumentId
        {
            get { return _HeaderBarCodeSeparatorDocumentId; }
            set
            {
                _HeaderBarCodeSeparatorDocumentId = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorDocumentId");
            }
        }

        public string HeaderBarCodeSeparatorDocumentNatureName
        {
            get { return _HeaderBarCodeSeparatorDocumentNatureName; }
            set
            {
                _HeaderBarCodeSeparatorDocumentNatureName = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorDocumentNatureName");
            }
        }

        public string HeaderBarCodeSeparatorDocumentItemName
        {
            get { return _HeaderBarCodeSeparatorDocumentItemName; }
            set
            {
                _HeaderBarCodeSeparatorDocumentItemName = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorDocumentItemName");
            }
        }

        public string HeaderBarCodeSeparatorDocumentPdfMerge
        {
            get { return _HeaderBarCodeSeparatorDocumentPdfMerge; }
            set
            {
                _HeaderBarCodeSeparatorDocumentPdfMerge = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorDocumentPdfMerge");
            }
        }

        public string HeaderBarCodeSeparatorDocumentDeleteBarCodePage
        {
            get { return _HeaderBarCodeSeparatorDocumentDeleteBarCodePage; }
            set
            {
                _HeaderBarCodeSeparatorDocumentDeleteBarCodePage = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorDocumentDeleteBarCodePage");
            }
        }

        public string HeaderBarCodeSeparatorDocumentManageError
        {
            get { return _HeaderBarCodeSeparatorDocumentManageError; }
            set
            {
                _HeaderBarCodeSeparatorDocumentManageError = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorDocumentManageError");
            }
        }

        public string HeaderBarCodeSeparatorDocumentInfLimit
        {
            get { return _HeaderBarCodeSeparatorDocumentInfLimit; }
            set
            {
                _HeaderBarCodeSeparatorDocumentInfLimit = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorDocumentInfLimit");
            }
        }

        public string HeaderBarCodeSeparatorDocumentSupLimit
        {
            get { return _HeaderBarCodeSeparatorDocumentSupLimit; }
            set
            {
                _HeaderBarCodeSeparatorDocumentSupLimit = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorDocumentSupLimit");
            }
        }

        public Boolean RadTabItemSepFolderIsEnabled
        {
            get { return _RadTabItemSepFolderIsEnabled; }
            set
            {
                _RadTabItemSepFolderIsEnabled = value;
                RaisePropertyChanged("RadTabItemSepFolderIsEnabled");
            }
        }

        public Boolean RadTabItemSepFolderIsSelected
        {
            get { return _RadTabItemSepFolderIsSelected; }
            set
            {
                _RadTabItemSepFolderIsSelected = value;
                RaisePropertyChanged("RadTabItemSepFolderIsSelected");
            }
        }

        public string RadTabItemHeaderSepFolder
        {
            get { return _RadTabItemHeaderSepFolder; }
            set
            {
                _RadTabItemHeaderSepFolder = value;
                RaisePropertyChanged("RadTabItemHeaderSepFolder");
            }
        }

        public string SepFolderItemList
        {
            get { return _SepFolderItemList; }
            set
            {
                _SepFolderItemList = value;
                RaisePropertyChanged("SepFolderItemList");
            }
        }

        public string HeaderBarCodeSeparatorFolderCorresp
        {
            get { return _HeaderBarCodeSeparatorFolderCorresp; }
            set
            {
                _HeaderBarCodeSeparatorFolderCorresp = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderCorresp");
            }
        }

        public string HeaderBarCodeSeparatorFolderIndexname
        {
            get { return _HeaderBarCodeSeparatorFolderIndexname; }
            set
            {
                _HeaderBarCodeSeparatorFolderIndexname = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderIndexname");
            }
        }

        public string HeaderBarCodeSeparatorFolderIndexStartChar
        {
            get { return _HeaderBarCodeSeparatorFolderIndexStartChar; }
            set
            {
                _HeaderBarCodeSeparatorFolderIndexStartChar = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderIndexStartChar");
            }
        }

        public string HeaderBarCodeSeparatorFolderIndexEndChar
        {
            get { return _HeaderBarCodeSeparatorFolderIndexEndChar; }
            set
            {
                _HeaderBarCodeSeparatorFolderIndexEndChar = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderIndexEndChar");
            }
        }

        public string HeaderBarCodeSeparatorFolderDocLimit
        {
            get { return _HeaderBarCodeSeparatorFolderDocLimit; }
            set
            {
                _HeaderBarCodeSeparatorFolderDocLimit = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderDocLimit");
            }
        }

        public string HeaderBarCodeSeparatorFolderPageLimit
        {
            get { return _HeaderBarCodeSeparatorFolderPageLimit; }
            set
            {
                _HeaderBarCodeSeparatorFolderPageLimit = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderPageLimit");
            }
        }

        public string HeaderBarCodeSeparatorFolderDocumentLimit
        {
            get { return _HeaderBarCodeSeparatorFolderDocumentLimit; }
            set
            {
                _HeaderBarCodeSeparatorFolderDocumentLimit = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderDocumentLimit");
            }
        }

        public string HeaderBarCodeSeparatorFolderInfLimit
        {
            get { return _HeaderBarCodeSeparatorFolderInfLimit; }
            set
            {
                _HeaderBarCodeSeparatorFolderInfLimit = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderInfLimit");
            }
        }

        public string HeaderBarCodeSeparatorFolderSupLimit
        {
            get { return _HeaderBarCodeSeparatorFolderSupLimit; }
            set
            {
                _HeaderBarCodeSeparatorFolderSupLimit = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderSupLimit");
            }
        }

        public string HeaderBarCodeSeparatorFolderDeleteCAB
        {
            get { return _HeaderBarCodeSeparatorFolderDeleteCAB; }
            set
            {
                _HeaderBarCodeSeparatorFolderDeleteCAB = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderDeleteCAB");
            }
        }

        public string HeaderBarCodeSeparatorFolderErrorManagment
        {
            get { return _HeaderBarCodeSeparatorFolderErrorManagment; }
            set
            {
                _HeaderBarCodeSeparatorFolderErrorManagment = value;
                RaisePropertyChanged("HeaderBarCodeSeparatorFolderErrorManagment");
            }
        }		                                   

        #endregion Properties

        #region Constructor and Initialization

        public BarCodeTabViewModel()
            : base()
        {
            CanCloseTab = true;

            //Icon.
            TabIcon = new Uri("/Rio.Manager.Application;component/Assets/Images/BarCode_Onglet_Manage.png", UriKind.Relative);
        }

        /// <summary>Inits the commands.</summary>
        public override void InitCommands()
        {
            //Command initialization.
            InitializationCommand = new RelayCommand(Initialization);
            BarCodeCreateCommand = new RelayCommand(BarCodeCmdCreate);
            BarCodeActivateDeactiveCommand = new RelayCommand(BarCodeCmdActivateDeactivate);
            BarCodeModifyCommand = new RelayCommand(BarCodeCmdModify);
            BarCodeDeleteCommand = new RelayCommand(BarCodeCmdDelete);
            BarCodeRefreshCommand = new RelayCommand(BarCodeCmdRefresh); 
        }

        /// <summary>Initializations this instance.</summary>
        private void Initialization()
        {
            InitLabels();
            InitBarCodeTable();
            InitsProperties();

            //Message to refresh barcode consultation register.
            Messenger.Default.Register<NotificationMessage>(this, InitBarCodeTable);
        }

        /// <summary>Inits the labels.</summary>
        public override void InitLabels()
        {
            //Retrieves the labels.
            TabTitle = Resx.GetLabel(ResxRioManager.BARCODE_MANAGE);
            BarCodeTitleList = Resx.GetLabel(ResxRioManager.BARCODE_TITLE_LIST);
            NewBarCode = Resx.GetLabel(ResxCommon.NEW);
            ActivateBarCode = Resx.GetLabel(ResxCommon.ACTIVATE);
            ModifyBarCode = Resx.GetLabel(ResxCommon.MODIFY);
            DeleteBarCode = Resx.GetLabel(ResxCommon.DELETE);
            RefreshBarCode = Resx.GetLabel(ResxCommon.REFRESH);
            HeaderBarCodeEnable = Resx.GetLabel(ResxRioManager.BARCODE_STATUT);
            HeaderBarCodeParamCode = Resx.GetLabel(ResxRioManager.BARCODE_IDENTIFIER);
            HeaderBarCodeName = Resx.GetLabel(ResxRioManager.BARCODE_NAME);
            HeaderBarCodeDescription = Resx.GetLabel(ResxRioManager.BARCODE_DESCRIPTION);
            HeaderBarCodePrefix = Resx.GetLabel(ResxRioManager.BARCODE_PREFIX);
            HeaderBarCodeType = Resx.GetLabel(ResxRioManager.BARCODE_TYPE);
            HeaderBarCodeFunction = Resx.GetLabel(ResxRioManager.BARCODE_FUNCTION);
            RadTabItemHeaderSepDocument = Resx.GetLabel(ResxRioManager.BARCODE_SEP_DOC_TITLE);
            SepDocItemList = Resx.GetLabel(ResxRioManager.BARCODE_SEP_DOC_ITEM_LIST);
            HeaderBarCodeSeparatorDocumentId = Resx.GetLabel(ResxRioManager.BARCODE_SEP_DOC_ID);
            HeaderBarCodeSeparatorDocumentNatureName = Resx.GetLabel(ResxRioManager.BARCODE_SEP_DOC_NATURE_NAME);
            HeaderBarCodeSeparatorDocumentItemName = Resx.GetLabel(ResxRioManager.BARCODE_SEP_DOC_ITEM_NAME);
            HeaderBarCodeSeparatorDocumentPdfMerge = Resx.GetLabel(ResxRioManager.BARCODE_SEP_DOC_PDF_MERGE);
            HeaderBarCodeSeparatorDocumentDeleteBarCodePage = Resx.GetLabel(ResxRioManager.BARCODE_SEP_DOC_DELETE_BARCODE_PAGE);
            HeaderBarCodeSeparatorDocumentManageError = Resx.GetLabel(ResxRioManager.BARCODE_SEP_DOC_MANAGMENT_ERROR);
            HeaderBarCodeSeparatorDocumentInfLimit = Resx.GetLabel(ResxRioManager.BARCODE_SEP_DOC_INF_LIMIT);
            HeaderBarCodeSeparatorDocumentSupLimit = Resx.GetLabel(ResxRioManager.BARCODE_SEP_DOC_SUP_LIMIT);
            RadTabItemHeaderSepFolder = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_TITLE);
            SepFolderItemList = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_ITEM_LIST);
            HeaderBarCodeSeparatorFolderCorresp = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_CORRESP);
            HeaderBarCodeSeparatorFolderIndexname = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_INDEX_NAME);
		    HeaderBarCodeSeparatorFolderIndexStartChar = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_INDEX_START);
		    HeaderBarCodeSeparatorFolderIndexEndChar = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_INDEX_END);
            HeaderBarCodeSeparatorFolderDocLimit = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_DOC_LIMIT);
		    HeaderBarCodeSeparatorFolderPageLimit = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_PAGE_LIMIT);
		    HeaderBarCodeSeparatorFolderDocumentLimit = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_DOCUMENT_LIMIT);
	        HeaderBarCodeSeparatorFolderInfLimit = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_INF_LIMIT);
            HeaderBarCodeSeparatorFolderSupLimit = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_SUP_LIMIT);
		    HeaderBarCodeSeparatorFolderDeleteCAB = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_DELETE_CAB);
		    HeaderBarCodeSeparatorFolderErrorManagment = Resx.GetLabel(ResxRioManager.BARCODE_SEP_FOLDER_ERROR_MANAGMENT);
        }

        /// <summary>Inits the properties.</summary>
        public void InitsProperties()
        {
            CanActivateBarCode = false;
            CanUpdateBarCode = false;
            CanDeleteBarCode = false;
            RadTabItemSepDocumentIsEnabled = true;
            RadTabItemSepFolderIsEnabled = true;
            RadTabItemSepDocumentIsSelected = true;
            RadTabItemSepFolderIsSelected = true;
        }

        public void InitBarCodeTable(NotificationMessage p_oMsg = null)
        {
            if ((p_oMsg == null) || (p_oMsg.Notification.Equals("RefreshConsultBarcode")))
            {
                BusyIndicator.Clear();
                BusyIndicator.AddBusyTask();

                //Barcode Table Initialization.
                BusinessEntitiesDomainContext l_oBEDomainContext = new BusinessEntitiesDomainContext();
                var query = l_oBEDomainContext.GetAllTheBarCodesQuery();
                l_oBEDomainContext.Load(query, OnGetBarCodeListCallback, null);

                //Initialize the BarcodeInformationsSelected property.
                BarCodeInformationsSelected = new ObservableCollection<Barcode>();
            }
        }

        #endregion Constructor and Initialization

        #region Methods

        /// <summary>Gets barcode informations to update.</summary>        
        private void RetrievesBarCodeInformationToUpdate()
        {
            //Retrieves barcode Information.
            BarCodeAddTabViewModel newBarCodeToUpdate = ViewModelLocator.BarCodeAddTabStatic;
            newBarCodeToUpdate.BarCodeInformationToUpdate = BarCodeInformationsSelected;
            List<BarcodeSeparator> l_oBarCodeSeparatorItem = BarCodeInformationsSelected[0].BarCodeSeparatorList.ToList();

            //Modify Mode.
            newBarCodeToUpdate.IsModifyMode = true;

            //Retrieves Organization barcode.
            Organizations = new ObservableCollection<Organization>();
            OrganizationComparer L_oOrganizationComparer = new OrganizationComparer();
            foreach (Group g in GlobalWebContext.CurrentUser.GroupList)
            {
                foreach (Organization org in g.OrganizationList)
                {
                    if (!Organizations.Contains(org, L_oOrganizationComparer))
                    {
                        if (GlobalWebContext.OrganizationHaveFolderTypeRight(org, AppDisplayMode.Admin))
                        {
                            Organizations.Add(org);
                        }
                    }
                }
            }            
            foreach (Organization l_oOragnisationBarCodetoUpdate in Organizations)
            {
                if (l_oOragnisationBarCodetoUpdate.Identifier == l_oBarCodeSeparatorItem[0].OrganizationId)
                {
                    newBarCodeToUpdate.SelectedOrganization = l_oOragnisationBarCodetoUpdate;
                    break;
                }
            }

            //Retrieves FolderType.
            FolderTypes = new ObservableCollection<FolderType>();
            FolderTypeComparer L_oFolderTypeComparer = new FolderTypeComparer();
            if (newBarCodeToUpdate.SelectedOrganization != null)
            {
                foreach (FolderType FolderTypeInOrga in newBarCodeToUpdate.SelectedOrganization.FolderTypesList)
                {
                    foreach (Group UserGroup in GlobalWebContext.CurrentUser.GroupList)
                    {
                        if ((UserGroup.FolderTypeRigthList.Contains(FolderTypeInOrga, L_oFolderTypeComparer)) && ((UserGroup.IsAdministrator)))
                        {
                            FolderTypes.Add(FolderTypeInOrga);
                        }
                    }
                }
                foreach (FolderType l_oFolderTypeConnecteurtoUpdate in FolderTypes)
                {
                    if (l_oFolderTypeConnecteurtoUpdate.Identifier == l_oBarCodeSeparatorItem[0].FolderTypeId)
                    {
                        newBarCodeToUpdate.SelectedDisplayBarCodeFunction = new DisplayBarCodeFunction();
                        newBarCodeToUpdate.SelectedFolderType = l_oFolderTypeConnecteurtoUpdate;
                        break;
                    }
                }
            }
            
            //Open the barcode added page for updated barcode.
            AddTab(newBarCodeToUpdate);
        }

        /// <summary>Active or deactive Barcode.</summary>
        private void SetJobBarCodeCmdActivateDeactivate(Boolean p_bCanActivateBarCodeEnabled)
        {
            //Save ActivateBarCode propertie value.
            string l_sSaveActivateBarCodeValue = ActivateBarCode;

            //Active or Inactive Button.
            if (p_bCanActivateBarCodeEnabled)
            {
                if (BarCodeInformationsSelected.Count != 0 )
                {
                    Boolean l_bBarCodeModifyStatut = BarCodeInformationsSelected[0].Enabled;
                    foreach (Barcode BarCodeInformationsSelectedItem in BarCodeInformationsSelected)
                    {
                        Boolean l_bBarCodeModifyStatutTemp = BarCodeInformationsSelectedItem.Enabled;
                        if (l_bBarCodeModifyStatutTemp != l_bBarCodeModifyStatut)
                        {
                            CanActivateBarCode = false;
                            ActivateBarCode = l_sSaveActivateBarCodeValue;
                            return;
                        }
                        l_bBarCodeModifyStatut = l_bBarCodeModifyStatutTemp;
                    }
                    ActiveBarCodeStatut = l_bBarCodeModifyStatut;
                    ActivateBarCode = ActiveBarCodeStatut ? Resx.GetLabel(ResxCommon.DEACTIVATE) : Resx.GetLabel(ResxCommon.ACTIVATE);
                }
            }
        }   

        #endregion Methods

        #region Commands

        /// <summary>Create a new barcode.</summary>
        public void BarCodeCmdCreate()
        {
            //Open the barcode added page.
            BarCodeAddTabViewModel newTabAdd = ViewModelLocator.BarCodeAddTabStatic;
            newTabAdd.IsModifyMode = false;
            newTabAdd.SelectedDisplayBarCodeFunction = new DisplayBarCodeFunction();
            newTabAdd.SelectedDisplayBarCodeTypologyType = new DisplayBarCodeType();
            newTabAdd.SelectedOrganization = null;
            newTabAdd.SelectedFolderType = null;
            AddTab(newTabAdd);              
        }

        /// <summary>Active or Deactive barcode list selected.</summary>
        public void BarCodeCmdActivateDeactivate()
        {
            //Variable declaration.
            string l_sBarCodeIdList = string.Empty;
            Boolean l_oCanDeleteBarCodeTemp = CanDeleteBarCode;
            Boolean l_oCanUpdateBarCodeTemp = CanUpdateBarCode;
            MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow();

            //BarCode Id List selected.
            foreach (Barcode l_oBarCodeListId in BarCodeInformationsSelected)
            {
                l_sBarCodeIdList = l_sBarCodeIdList + l_oBarCodeListId.Identifier + ";";
            }
            l_sBarCodeIdList = l_sBarCodeIdList.Substring(0, l_sBarCodeIdList.Length - 1);

            //Message user before deleting.
            L_oMessage = new MessageBoxChildWindow(String.Empty, string.Format(Resx.GetLabel(ResxRioManager.BARCODE_STATUS_MSG_CONFIRM), ActivateBarCode.ToLower()), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            L_oMessage.Show();
            L_oMessage.Closed += (s, ev) =>
            {
                if (L_oMessage.Result == MessageBoxResult.Yes)
                {
                    //Update status.
                    BusinessEntitiesDomainContext l_oBEDomainContext = new BusinessEntitiesDomainContext();
                    l_oBEDomainContext.UpdateStatusBarcodeList(l_sBarCodeIdList, ActiveBarCodeStatut, result =>
                    {
                        if (result.HasError)
                        {
                            //Error.
                            L_oMessage = new MessageBoxChildWindow(String.Empty, Resx.GetLabel(ResxRioManager.BARCODE_UPDATE_STATUS_ERROR) + Environment.NewLine + result.Error.Message, MessageBoxButtons.Ok, MessageBoxIcon.Error);
                            L_oMessage.Show();
                        }
                        else
                        {
                            //Succes.
                            L_oMessage = new MessageBoxChildWindow(String.Empty, Resx.GetLabel(ResxRioManager.BARCODE_UPDATE_STATUS_SUCCES), MessageBoxButtons.Ok, MessageBoxIcon.Information);
                            L_oMessage.Show();

                            //Refresh table.
                            InitBarCodeTable();
                        }
                    },
                                null);
                }
                else
                {
                    //Properties values.
                    CanDeleteBarCode = l_oCanDeleteBarCodeTemp;
                    CanUpdateBarCode = l_oCanUpdateBarCodeTemp;
                }
            };
            
        }

        /// <summary>Modify a barcode.</summary>
        public void BarCodeCmdModify()
        {
            //Variable declaration.            
            Boolean l_oCanDeleteBarCodeTemp = CanDeleteBarCode;
            Boolean l_oCanUpdateBarCodeTemp = CanUpdateBarCode;
            MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow();

            //Test only one barcode must be selected.
            switch (BarCodeInformationsSelected.Count)
            {
                case 0:
                    //Message user before modify.
                    L_oMessage = new MessageBoxChildWindow(String.Empty, Resx.GetLabel(ResxRioManager.BARCODE_UPDATE_NOTSELECTED), MessageBoxButtons.Ok, MessageBoxIcon.Warning);
                    L_oMessage.Show();
                    L_oMessage.Closed += (s, ev) =>
                    {
                        //Properties values.
                        CanDeleteBarCode = l_oCanDeleteBarCodeTemp;
                        CanUpdateBarCode = l_oCanUpdateBarCodeTemp;
                    };
                    break;
                case 1:
                    //Retrieves informations for update.
                    RetrievesBarCodeInformationToUpdate();

                    break;
                default:
                    //Only one barcode must be selected.
                    L_oMessage = new MessageBoxChildWindow(String.Empty, Resx.GetLabel(ResxRioManager.BARCODE_UPDATE_MOREONE), MessageBoxButtons.Ok, MessageBoxIcon.Warning);
                    L_oMessage.Show();
                    L_oMessage.Closed += (s, ev) =>
                    {
                        //Properties values.
                        CanDeleteBarCode = l_oCanDeleteBarCodeTemp;
                        CanUpdateBarCode = l_oCanUpdateBarCodeTemp;
                    };
                    break;
            }
        }

        /// <summary>Delete list of barcode.</summary>
        public void BarCodeCmdDelete()
        {
            //Variable declaration.
            string l_sBarCodeIdList = string.Empty;
            Boolean l_oCanDeleteBarCodeTemp = CanDeleteBarCode;
            Boolean l_oCanUpdateBarCodeTemp = CanUpdateBarCode;
            MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow();

            //BarCode Id List selected.
            foreach (Barcode l_oBarCodeListId in BarCodeInformationsSelected)
            {
                l_sBarCodeIdList = l_sBarCodeIdList + l_oBarCodeListId.Identifier + ";";
            }
            l_sBarCodeIdList = l_sBarCodeIdList.Substring(0, l_sBarCodeIdList.Length - 1);

            //Message user before deleting.
            L_oMessage = new MessageBoxChildWindow(String.Empty, Resx.GetLabel(ResxRioManager.BARCODE_DELETE_MSG_CONFIRM), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            L_oMessage.Show();
            L_oMessage.Closed += (s, ev) =>
            {
                if (L_oMessage.Result == MessageBoxResult.Yes)
                {
                    //Delete.
                    BusinessEntitiesDomainContext l_oBEDomainContext = new BusinessEntitiesDomainContext();
                    l_oBEDomainContext.DeleteBarcodeList(l_sBarCodeIdList, result =>
                    {
                        if (result.HasError)
                        {
                            //Error.
                            L_oMessage = new MessageBoxChildWindow(String.Empty, Resx.GetLabel(ResxRioManager.BARCODE_DELETE_ERROR) + Environment.NewLine + result.Error.Message, MessageBoxButtons.Ok, MessageBoxIcon.Error);
                            L_oMessage.Show();
                        }
                        else
                        {
                            //Succes.
                            L_oMessage = new MessageBoxChildWindow(String.Empty, Resx.GetLabel(ResxRioManager.BARCODE_DELETE_SUCCES), MessageBoxButtons.Ok, MessageBoxIcon.Information);
                            L_oMessage.Show();

                            //Refresh table.
                            InitBarCodeTable();
                        }
                    },
                                null);
                }
                else
                {
                    //Properties values.
                    CanDeleteBarCode = l_oCanDeleteBarCodeTemp;
                    CanUpdateBarCode = l_oCanUpdateBarCodeTemp;
                }
            };
        }

        /// <summary>Refresh a barcode.</summary>
        public void BarCodeCmdRefresh()
        {
            //Refresh table.
            InitBarCodeTable();
        }

        #endregion Commands   
 
        #region CallBack

        /// <summary>Gets the BarCode list.</summary>
        /// <param name="e">Barcode List</param>
        private void OnGetBarCodeListCallback(LoadOperation<Barcode> e)
        {
            BusyIndicator.RemoveBusyTask();

            if (!e.HasError)
            {
                //Built the barcode list.
                ObservableCollection<Barcode> l_oBarCodeInformationList = new ObservableCollection<Barcode>(e.Entities);
                BarCodeInformationList = new ObservableCollection<Barcode>();

                //Fill Function Name.
                foreach (Barcode l_oBarCodeItem in l_oBarCodeInformationList)
                {
                    Barcode l_oBarCodeTemp = new Barcode();
                    l_oBarCodeTemp.Identifier = l_oBarCodeItem.Identifier;
                    l_oBarCodeTemp.ParamCode = l_oBarCodeItem.ParamCode;
                    l_oBarCodeTemp.Name = l_oBarCodeItem.Name;
                    l_oBarCodeTemp.Description = l_oBarCodeItem.Description;
                    l_oBarCodeTemp.Enabled = l_oBarCodeItem.Enabled;
                    l_oBarCodeTemp.Prefix = l_oBarCodeItem.Prefix;
                    l_oBarCodeTemp.Type = l_oBarCodeItem.Type;
                    l_oBarCodeTemp.TypeLabel = l_oBarCodeItem.TypeLabel;
                    l_oBarCodeTemp.Function = l_oBarCodeItem.Function;
                    if (l_oBarCodeItem.Function.szGetDescription() == "FolderSeparator")
                    {
                        l_oBarCodeTemp.FunctionLabel = Resx.GetLabel(ResxRioManager.BARCODE_FUNCTION_FOLDER_SEPARATOR);
                    }
                    else if (l_oBarCodeItem.Function.szGetDescription() == "DocumentSeparator")
                    {
                        l_oBarCodeTemp.FunctionLabel = Resx.GetLabel(ResxRioManager.BARCODE_FUNCTION_DOCUMENT_SEPARATOR);
                    }   

                    foreach (BarcodeSeparator l_oBarCodeSeparatorItem in l_oBarCodeItem.BarCodeSeparatorList)
                    {
                        l_oBarCodeTemp.BarCodeSeparatorList.Add(l_oBarCodeSeparatorItem);
                    }

                    BarCodeInformationList.Add(l_oBarCodeTemp);   
                }

                //Inits the properties.
                InitsProperties();
            }
        }

        #endregion
    }
}
